const {
  defineConfig
} = require('@vue/cli-service')
const title = process.env.VUE_APP_TITLE || '后台管理系统' // 网页标题
const path = require('path');

function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    host: 'localhost',
    // 端口号，默认是 3000
    port: 8081,
    // 是否开启 https
    https: false,
  },
  // publicPath: './',
  configureWebpack: {
    output: {
      filename: 'bundle/[name].js',
      chunkFilename: 'bundle/[name].js',
      path: path.resolve(__dirname, 'dist'),

    },
  },
  chainWebpack: config => {

    config.module
      .rule('svg')
      .exclude.add(resolve('src/icons')) // 存放 svg 目录的目录
      .end()
    config.module
      .rule('icons')
      .test(/\.svg$/)
      .include.add(resolve('src/icons')) // 存放 svg 目录的目录
      .end()
      .use('svg-sprite-loader')
      .loader('svg-sprite-loader')
      .options({
        symbolId: 'icon-[name]'
      })
      .end()
    config
      .plugin('html')
      .tap(args => {
        args[0].title = title
        return args
      })
      .end()
  },
})